import os

from pip._vendor.distlib.compat import raw_input

'''
代码行数统计工具
'''
class countcode:
    num1 = 0

    def __init__(self, dirth):
        self.dirth = dirth

    def count(self, namelast):
        for dirpath, dirnames, filenames in os.walk(self.dirth):
            for filename in filenames:
                if filename.find(namelast) > 0:
                    filename = dirpath.replace("\\", "/") + '/' + filename
                    print("filename:" + filename)
                    vv = open(filename, "rb")
                    try:
                       for bb in vv:
                           # if bb.__len__() > 1:
                           self.num1 += 1
                    finally:
                        vv.close()
    def get_count(self):
        # print(self.num1)
        return self.num1


if __name__ == "__main__":
    num2 = 0
    url = raw_input("请输入需要统计的文件夹路径:")
    url = url.replace("\\", "/")
    print("输入的文件夹路径为:" + url)
    namelastlist = input('请输入需要统计的文件后缀名集合，例子：".css",".java",".ts",".scss",".html"')
    namelasts = namelastlist.replace('"', '').split(",")
    print(namelasts)
    countcode1 = countcode(url)
    print("开始统计......")
    for aa in namelasts:
        countcode1.count(aa)
    num2 = countcode1.get_count()
    print("代码行数总计:" + str(num2))
    print("请问你是否需要退出？")
    i = "N"
    while i != "Y":
        i = input("请输入任意键退出")
        break
